﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sales.aspx.cs" Inherits="Sales_Sales" %>
<html>
<head>
<title>零售开票</title>
<link href="../css/adminCss.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/rl.js"></script>
<script type="text/javascript" src="../js/submit.js"></script>
<script type="text/javascript">//-------------通过型号编号获取产品信息-----------------------------------------------------------
var xmlHttp1; 
var ajaxresponsevalue1;
function createXMLHttpRequest1() { 
    if (window.ActiveXObject) { 
        xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    else if (window.XMLHttpRequest) { 
        xmlHttp1 = new XMLHttpRequest(); 
    } 
} 

function startRequest(type) {  
    if(document.getElementById('TextBox1').value!=''||document.getElementById('Text1').value!=''){
        document.getElementById('Msg').innerHTML = "正在获取商品信息...";
        document.getElementById("Msg").style.visibility="visible";
        createXMLHttpRequest1(); 
        xmlHttp1.onreadystatechange = handleStateChange; 
        xmlHttp1.open("POST",'DataCode.aspx?type='+escape(type)+'&id='+escape(document.getElementById('TextBox1').value)+"&ModelId="+escape(document.getElementById('Text1').value), true); 
        xmlHttp1.send(null); 
    }
} 

function handleStateChange() { 
    if(xmlHttp1.readyState == 4) { 
        if(xmlHttp1.status == 200) { 
        //alert(xmlHttp1.responseText);
        getDownListData(xmlHttp1.responseText);		    
        }
         
    } 
} 

function getDownListData(paramValue1)
{
    if(paramValue1!="")//返回值
    {
       document.getElementById("HidRest").value=paramValue1.split(',')[1];
       document.getElementById("Label2").innerText=paramValue1.split(',')[2];  
        //document.getElementById("lblRetail").innerText=paramValue.split(',')[3];
       document.getElementById("lblToTal").innerText=paramValue1.split(',')[2];//应收单价
       document.getElementById("lblTotalPractical").innerText=paramValue1.split(',')[2];//应收单价
       document.getElementById("lblBrand").innerText=paramValue1.split(',')[4];//
       document.getElementById("Text1").value=paramValue1.split(',')[6];
       document.getElementById("HidBrand").value=paramValue1.split(',')[4];
       document.getElementById("lblComoName").innerText=paramValue1.split(',')[5];
       document.getElementById("HidName").value=paramValue1.split(',')[5];
       document.getElementById("lblUnits").innerText=paramValue1.split(',')[7];
       document.getElementById("HidUnit").value=paramValue1.split(',')[7];
       document.getElementById("TextBox1").value=paramValue1.split(',')[8];
       document.getElementById("HidPH").value=paramValue1.split(',')[9];
       document.getElementById("txtCmoney").value=paramValue1.split(',')[2];
       document.getElementById("txtpractical").value=paramValue1.split(',')[2];
       document.getElementById("HidProc").value=paramValue1.split(',')[10];
       document.getElementById("HFRKLX").value=paramValue1.split(',')[11];
       document.getElementById("HFCKID").value=paramValue1.split(',')[12];
       document.getElementById("HFtype").value=paramValue1.split(',')[13];
       document.getElementById("HFHDJ").value=paramValue1.split(',')[14];
       document.getElementById("HFNUM").value=paramValue1.split(',')[15];
       document.getElementById("Hidsj2").value+="1";
       document.getElementById("btnAd").disabled="";
       document.getElementById("HFjyjs").value=paramValue1.split(',')[2];
       document.getElementById("btnAd").focus();
       
       //生成库存数量下拉表
        var d = document.getElementById("SelNum");    
        d.options.length=0;//删除全部
        var num=parseInt(paramValue1.split(',')[15])
        if(num>0){
            for(i=0;i<=num;i++){
            d.options.add( new Option(i,i) );
            }
            document.getElementById("txtNum").value="1";
        }
         
    }else{
       document.getElementById("HidRest").value="";
       document.getElementById("Label2").innerText="";  
        //document.getElementById("lblRetail").innerText=paramValue.split(',')[3];
       document.getElementById("lblToTal").innerText="";
       document.getElementById("lblTotalPractical").innerText="";
       document.getElementById("lblBrand").innerText="";
       //document.getElementById("Text1").value="";
       document.getElementById("HidBrand").value="";
       document.getElementById("lblComoName").innerText="";
       document.getElementById("HidName").value="";
       document.getElementById("lblUnits").innerText="";
       document.getElementById("HidUnit").value="";
       //document.getElementById("TextBox1").value="";
       document.getElementById("HidPH").value="";
       document.getElementById("txtCmoney").value="";
       document.getElementById("txtpractical").value="";
       document.getElementById("txtpractical").value="";
       document.getElementById("HidProc").value="";
       document.getElementById("HFRKLX").value="";
       document.getElementById("HFCKID").value="";
       document.getElementById("HFtype").value="";
       document.getElementById("HFHDJ").value="";
       document.getElementById("HFNUM").value="";
       document.getElementById("txtNum").value="0";
       document.getElementById("SelNum").options.length=0;//删除全部
       document.getElementById("btnAd").disabled=true;
    }
    document.getElementById("Msg").style.visibility="hidden";
}
//-------------END 通过型号编号获取产品信息-----------------------------------------------------------

function end()//获取客户信息资料是否完整
{

    if(document.getElementById("HidCountNum").value!="0" && document.getElementById("txtGuest").value!=""&&document.getElementById("txtGuestName").value!=""&&document.getElementById("txtAddress").value!=""&&document.getElementById("txtTel").value!="")
    {
        document.getElementById("btnAdd").disabled="";
    }
    else
    {
        document.getElementById("btnAdd").disabled=true;       
    }
}

function account(flag)
{
    if(flag==1)//输入成交价时,同意实收的值=成交价
    {
        document.getElementById("txtpractical").value=document.getElementById("txtCmoney").value
    }
    var sl=document.getElementById("txtNum").value;//数量
    var dj=document.getElementById("txtCmoney").value;//应收单价
    var ssdj=document.getElementById("txtpractical").value;//实收单价

    if(sl!=""&&dj!=""&&!isNaN(sl)&&!isNaN(dj))
    {
        document.getElementById("lblToTal").innerText=sl*dj;
        document.getElementById("lblTotalPractical").innerText=sl*ssdj;
    }
}
    
function check(id)
{
    if( document.getElementById("TextBox1").value=="")
    {
        alert(" 请输入商品信息");
        return false;
    }
    if(parseFloat(document.getElementById("txtNum").value) <= 0)
    {
        alert('数量不能小于0！')
        return false;
    }
    if( document.getElementById("ddlUser").value=="")
    {
        alert("选择销售员");
        return false;
    }
     if(document.getElementById("HFRKLX").value!='赠品')
     {
      if(parseFloat(document.getElementById("HFHDJ").value) > parseFloat(document.getElementById("txtCmoney").value))
       {
       alert("成交价输入不正确！");
       document.getElementById("txtCmoney").focus();
       return false;
       }
       checknull(id);
       }
     }

    function PrintData(id)
    {
    if(id!="")
    {
        window.open("DrawPrint1.aspx?id="+id,"","width=800px,height=650px,left=100px,top=30px,scrollbars=yes");
        return false;
    }
    return false;
}
</script>

<link href="../js/loading.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript" src="../js/loading.js" charset="gb2312"></script>
<body>
    <form id="form1" runat="server" onSubmit=" checknull(this)">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td align="center" width="31" height="22">
                    <img src="../images/module.gif" width="20" height="22"></td>
                <td style="width: 335px">
                    <asp:Label ID="lblPath" runat="server"></asp:Label></td>
                <td width="990" align="right">&nbsp;
              </td>
            </tr>
      </table>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td bgcolor="#3CB6E5" height="5px">
                </td>
            </tr>
        </table>
        <table border="0" width="100%" cellpadding="1" cellspacing="1" class="tabGg">
            <tr>
                <td colspan="6" bgcolor="#FFFFFF" height="27">
					<div class="left">单号：<asp:Label ID="lblDh" runat="server"></asp:Label>
                    <div id="Msg" style="position: absolute; width: 120px; height: 20px; z-index: 1;border: 1px solid #ff0000; background-color: #FEEED3; layer-background-color: #FEEED3;filter: alpha(opacity=50); visibility: hidden;"></div></div>
				</td>
            </tr>
            <tr>
                <th width="15%" height="27"  class="r_bg nobr">
                    型号编号：</th>
                <td   class="right_bg">
                    <input name="TextBox1" type="text" style="width: 100px" id="TextBox1"   onKeyUp="startRequest(1)" onchange="startRequest(1)" class="input1" runat="server" /></td>
                <th width="15%"  class="r_bg nobr">规格型号：</th>
                <td   class="right_bg" ><input name="Text1" type="text" style="width: 100px" id="Text1" onKeyUp="startRequest(2)"  onchange="startRequest(2)"  class="input1" runat="server" /></td>
                <th width="15%"  class="r_bg">销售员：</th>
                <td height="27"  class="right_bg" >
                <asp:DropDownList ID="ddlUser" runat="server">
                      <asp:ListItem Value="">－选择销售员－</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>
            <tr>
                <th height="28"  class="r_bg" >商品品牌：</th>
                <td  class="right_bg"> <asp:Label ID="lblBrand" runat="server" ForeColor="Red"></asp:Label>                </td>
                <th  class="r_bg  nobr">商品名称：</th>
                <td  class="right_bg" ><asp:Label ID="lblComoName" runat="server" ForeColor="Red"></asp:Label></td>
                <th  class="r_bg nobr"><div id="Div1" style="position: absolute; line-height:20px; height: 20px; z-index: 1;border: 1px solid #ff0000; background-color: #FEEED3; layer-background-color: #FEEED3;filter: alpha(opacity=90); visibility: hidden;">经批准后才可编辑[实收价],否则请与成交价保持一致！</div>
                    成交价：</th>
                <td height="28"  class="right_bg">
                    单价：<input name="txtCmoney" type="text" style="width: 50px;" value="0" class="input1" id="txtCmoney"   onfocus="if(this.value==0)this.value=''" onBlur="if(this.value=='')this.value=0"    onkeyup="value=value.replace(/[^\d]/g,'');account(1)" onchange="value=value.replace(/[^\d]/g,'');account(1)"  runat="server" />元 合计：￥<asp:Label ID="lblToTal" runat="server" ForeColor="Red" Text="0"/></td>
            </tr>
            <tr>
                <th height="28"  class="r_bg">
                    价格：</th>
                <td  class="right_bg" "><asp:Label ID="Label1" runat="server"></asp:Label> 
                <asp:Label ID="Label2" runat="server"></asp:Label>               </td>
               <th  class="r_bg">数 &nbsp; 量：</th>
                <td  class="right_bg" ><input name="text" type="text" class="input1"  id="txtNum" style="width: 50px"  value="0" runat="server"  readonly="readOnly"  />
                    <select id="SelNum" name="SelNum" onchange="this.form.txtNum.value=this.value;account(0)">
                        <option selected="selected" value="0">0</option>
                    </select>
                <asp:Label ID="lblUnits" runat="server" ForeColor="#0000C0"></asp:Label></td>
                <th  class="r_bg">
                    同意实收：</th>
                <td height="28"  class="right_bg">
                    单价：<input name="txtpractical" type="text" style="width: 50px;" value="0" class="input1" id="txtpractical"   onfocus="if(this.value==0)this.value='';document.getElementById('Div1').style.visibility='visible';" onBlur="if(this.value=='')this.value=0;document.getElementById('Div1').style.visibility='hidden';"    onkeyup="value=value.replace(/[^\d]/g,'');account(0)"  onchange="value=value.replace(/[^\d]/g,'');account(0)"  runat="server"  />元
                    合计：￥<asp:Label ID="lblTotalPractical" runat="server" ForeColor="Red" Text="0"/> </td>
            </tr>
      </table>
                    <asp:GridView ID="gvData" runat="server" Width="100%" CssClass="gridview" AutoGenerateColumns="False">
                        <PagerSettings Visible="False" />
                        <Columns>
                            <asp:BoundField HeaderText="品牌" DataField="LS_band">
                                <ItemStyle HorizontalAlign="Center" />                            </asp:BoundField>
                            <asp:BoundField HeaderText="商品名称" DataField="LS_name">
                                <ItemStyle HorizontalAlign="Center" />                            </asp:BoundField>
                            <asp:BoundField HeaderText="型号" DataField="LS_modul">
                                <ItemStyle HorizontalAlign="Center" />                            </asp:BoundField>
                            <asp:BoundField HeaderText="数量" DataField="LS_num">
                                <ItemStyle HorizontalAlign="Center" />                            </asp:BoundField>
                            <asp:TemplateField HeaderText="单价(元)">
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("LS_price","{0:f2}") %>'></asp:Label>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="金额(元)">
                                <ItemTemplate>
                                    <asp:Label ID="Label0" runat="server" Text='<%# Bind("LS_TotalMoney","{0:f2}") %>'></asp:Label>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="单位" DataField="LS_unit">
                                <ItemStyle HorizontalAlign="Center" />
                                </asp:BoundField>
                            <asp:BoundField HeaderText="销售员" DataField="StaffName">
                                <ItemStyle HorizontalAlign="Center" />
                                </asp:BoundField>
                            <asp:TemplateField HeaderText="删除">
                                <ItemTemplate>
                                    <asp:LinkButton ID="linkDel" CommandArgument='<%#Eval("id") %>' runat="server" ForeColor="Red"
                                        OnClick="linkDel_Click">删除</asp:LinkButton>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    <table width="100%" border="1">
                        <tr>
                            <td style="width: 407px">                            </td>
                            <td style="width: 98px">                            </td>
                            <td>                            </td>
                        </tr>
                        <tr>
                            <td style="width: 407px" align="center">
                                本单合计</td>
                            <td style="width: 98px">
                                <asp:Label ID="lblXnum" runat="server" ForeColor="Red" Text="0"></asp:Label></td>
                            <td>
                                <asp:Label ID="lblXmoney" runat="server" ForeColor="Red" Text="0"></asp:Label></td>
                        </tr>
                        <tr>
                            <td style="width: 407px" align="center">
                                同意实收</td>
                            <td style="width: 98px">
                                <asp:Label ID="lblHnum" runat="server" ForeColor="Red" Text="0"></asp:Label></td>
                            <td>
                                <asp:Label ID="lblHMoney" runat="server" ForeColor="Red" Text="0"></asp:Label></td>
                        </tr>
                    </table><div class="center margin_bottom2 margin_top2"><asp:Button ID="btnAd" CssClass="submit" runat="server" Text="添加商品" OnClientClick="return check(this.form)"    OnClick="btnAd_Click" Enabled="False" /></div>
			
        <table border="0" width="100%" cellpadding="1" cellspacing="1" class="tabGg">
            <tr>
                <td width="15%" height="28"  class="r_bg" >送货日期：</td>
                <td  class="right_bg" colspan="3">
                    <asp:TextBox ID="TextBox3" runat="server"  CssClass="input1" onclick="SelectDate(this.name)"></asp:TextBox></td>
                <td  class="r_bg" width="15%"></td>
                <td height="28"  class="right_bg"></td>
            </tr>
            <tr>
                <td  class="r_bg" >
                    客户名称：</td>
                <td  class="right_bg">
                    <asp:TextBox ID="txtGuest" runat="server" CssClass="input1" onkeyup="end()" ></asp:TextBox> *</td>
                <td width="15%"  class="r_bg">
                    联系人：</td>
                <td  class="right_bg" >
                    <asp:TextBox ID="txtGuestName" runat="server" CssClass="input1" onkeyup="end()" ></asp:TextBox>                *</td>
                <td  class="r_bg">
                    电话：</td>
                <td  class="right_bg" >
                    <asp:TextBox ID="txtTel" runat="server" CssClass="input1" onkeyup="end()" ></asp:TextBox>
                    *</td>
            </tr>
            <tr>
                <td  class="r_bg nobr" >联系地址：</td>
                <td  class="right_bg"><asp:TextBox ID="txtAddress" runat="server" CssClass="input1" onkeyup="end()" ></asp:TextBox>
                    *</td>
                    <td  class="r_bg"><span class="r_bg nobr" >保修年限：</span></td>
              <td  class="right_bg"><asp:TextBox ID="txtWarr" runat="server" onkeyup="value=value.replace(/[^\d]/g,'');" CssClass="input1"   ForeColor="#0000C0" >0</asp:TextBox>       年</td>
                    <td  class="r_bg">备注：</td>
                    <td  class="right_bg"><asp:TextBox ID="txtContent" runat="server" CssClass="input1" ></asp:TextBox></td>
            </tr>
            <tr>
                <td  class="r_bg" >销售日期：</td>
                <td  class="right_bg"><asp:TextBox ID="txtSdate" runat="server" CssClass="input1" Width="80px"  onclick="SelectDate(this.name)"></asp:TextBox></td>
                    <td  class="r_bg">收银员：</td>
                    <td  class="right_bg"><asp:Label ID="lblName" runat="server"></asp:Label></td>
                    <td  class="r_bg nobr"></td>
                    <td  class="right_bg"></td>
            </tr>
            <tr>
                <td  class="r_bg">                
        <asp:HiddenField ID="HidCountNum" runat="server" />
        </td>
                <td colspan="5"  class="right_bg">
                    <asp:Button ID="btnAdd" CssClass="submit" runat="server" Text="确认付款"   OnClick="btnAdd_Click" Enabled="False" />
                    &nbsp; &nbsp;
                    <asp:CheckBox ID="isprint"  runat="server" Checked="True" Text="是否打印" /></td>
            </tr>
        </table>
        <asp:HiddenField ID="Hidware" runat="server" />
        <asp:HiddenField ID="HidRest" runat="server" />
        <asp:HiddenField ID="hidPH" runat="server" />
        <asp:HiddenField ID="Hidid" runat="server" />
        <asp:HiddenField ID="HidBrand" runat="server" />
        <asp:HiddenField ID="HFCKID" runat="server" />
        <asp:HiddenField ID="HFjyjs" runat="server" />
        <asp:HiddenField ID="hidsj" runat="server" />
        <asp:HiddenField ID="HidName" runat="server" />
        <asp:HiddenField ID="HidUnit" runat="server" />
        <asp:HiddenField ID="Hidsj2" runat="server" />
        <asp:HiddenField ID="HFNUM" runat="server" />
        <asp:HiddenField ID="HidProc" runat="server" />
        <asp:HiddenField ID="HFtype" runat="server" />
        <asp:HiddenField ID="HFHDJ" runat="server" />
        <asp:HiddenField ID="HFRKLX" runat="server" />
    </form>
</body>
</html>
